from rest_framework.generics import ListAPIView

from . import models, serializers


from rest_framework.filters import OrderingFilter, SearchFilter

from .filters import LimitFilter

from .paginations import CoursePageNumberPagination, CourseLimitOffsetPagination, CourseCursorPagination

from django_filters.rest_framework import DjangoFilterBackend
from .filters import CourseFilterSet


class FreeCourseListAPIView(ListAPIView):
    queryset = models.Course.objects.filter(is_delete=False, is_show=True).order_by('-orders').all()
    serializer_class = serializers.FreeCourseModelSerializer


    filter_backends = [OrderingFilter, SearchFilter, DjangoFilterBackend]

    ordering_fields = ['price', 'id', 'students']

    search_fields = ['name', 'brief']

    filter_class = CourseFilterSet


    pagination_class = CoursePageNumberPagination
    # pagination_class = CourseLimitOffsetPagination
    # pagination_class = CourseCursorPagination


class CategoryListAPIView(ListAPIView):
    queryset = models.CourseCategory.objects.filter(is_delete=False, is_show=True).order_by('orders').all()
    serializer_class = serializers.CategoryModelSerializer


from rest_framework.generics import RetrieveAPIView


class FreeCourseRetrieveAPIView(RetrieveAPIView):
    queryset = models.Course.objects.filter(is_delete=False, is_show=True).order_by('-orders').all()
    serializer_class = serializers.FreeCourseModelSerializer


class ChapterListAPIView(ListAPIView):
    queryset = models.CourseChapter.objects.filter(is_delete=False, is_show=True).all()
    serializer_class = serializers.CourseChapterModelSerializer

    filter_backends = [DjangoFilterBackend]
    filter_fields = ['course']
